using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameForKids
{
    public enum Oriention
    {
        horizontal,
        vertical,
    };
    class PongLine
    {
        public bool JustHit = false;
        public Vector2 PointA;
        public Vector2 PointB;
        public bool IsFence;
        public Oriention Direction;

        public PongLine(Vector2 pointA, Vector2 pointB, Oriention direction, bool isFence)
        {
            Direction = direction;
            IsFence = isFence;
            switch (direction)
            {
                case Oriention.horizontal:
                    if (pointA.X > pointB.X)
                    {
                        PointA = pointB;
                        PointB = pointA;
                    }
                    else
                    {
                        PointA = pointA;
                        PointB = pointB;
                    }
                    break;
                case Oriention.vertical:
                    if (pointA.Y > pointB.Y)
                    {
                        PointA = pointB;
                        PointB = pointA;
                    }
                    else
                    {
                        PointA = pointA;
                        PointB = pointB;
                    }
                    break;
            }
            
        }

        public bool CheckCut(Vector2 Position, int Range)
        {
            bool hit = true;
            int midX = (int)Position.X;
            int midY = (int)Position.Y;
            if ((PointA - PointB).Length() < 20)
            {
                if (Direction == Oriention.vertical)
                {
                    if (Math.Abs(PointA.X - midX) < Range && ((PointA.Y - Range) < midY && midY < (PointB.Y + Range)))
                    {
                        hit = true;
                    }
                    else
                    {
                        hit = false;
                    }
                }
                else
                {
                    if (Math.Abs(PointA.Y - midY) < Range && ((PointA.X - Range) < midX && midX < (PointB.X + Range)))
                    {
                        hit = true;
                    }
                    else
                    {
                        hit = false;
                    }
                }
            }
            else
            {
                if (Direction == Oriention.vertical)
                {
                    if (Math.Abs(PointA.X - midX) < Range && ((PointA.Y) < midY && midY < (PointB.Y)))
                    {
                        hit = true;
                    }
                    else
                    {
                        hit = false;
                    }
                }
                else
                {
                    if (Math.Abs(PointA.Y - midY) < Range && ((PointA.X) < midX && midX < (PointB.X)))
                    {
                        hit = true;
                    }
                    else
                    {
                        hit = false;
                    }
                }
            }

            if (JustHit == true)
            {
                if (hit == false)
                {

                    JustHit = false;
                }
                else
                {
                    hit = false;
                }
            }

            if (hit == true)
            {
                JustHit = true;
            }

            return hit;
        }

        public int HitSide(Vector2 Position, int Range)
        {
            int midX = (int)Position.X;
            int midY = (int)Position.Y;
            int location = 0;
            switch (Direction)
            {
                case Oriention.vertical:
                    if (PointA.X < midX)
                    {
                        location = 1;
                    }
                    else
                    {
                        location = 3;
                    }
                    break;
                case Oriention.horizontal:
                    if (PointA.Y < midY)
                    {
                        location = 2;
                    }
                    else
                    {
                        location = 4;
                    }
                    break;
            }
            return location;
        }
    }
}
